<?
require_once("inc_security.php");
//check quy?n them sua xoa
checkAddEdit("add");

	//Khai bao Bien
	$record_id 								= getValue("record_id");
    $fqgop = get_all_faq_group_options();
    
    $action = getValue('action', 'str', 'POST', '');
	//Call Class generate_form();
	$myform = new generate_form();
	//Lo?i b? chuc nang thay the Tag Html
	$myform->removeHTML(0);

	//Add table
	$myform->addTable($fs_table);
    
	//Warning Error!
	$errorMsg = "";
	
	if($action == 'edit' && isset($_POST['submit'])){
		$fac_name								= getValue("fac_name","str","GET","");
        $fac_alias								= getValue("fac_alias","str","GET","");
    	$fac_fg_id								= getValue("fac_fg_id","int","GET",'0');
        
		
        $myform->add("fac_name","fac_name", 0, 0, $fac_name, 1, translate_text("Tên danh mục không được để trống"), 0, "");
        $myform->add("fac_alias","fac_alias", 0, 0, $fac_alias, 1, translate_text("Alias không được để trống"), 0, "");
        $myform->add("fac_fg_id", "fac_fg_id", 1, 0, $fac_fg_id, 1, translate_text("Vui lòng chọn nhóm câu hỏi"),0,"");
        
		$errorMsg .= $myform->checkdata();
		if($errorMsg == ""){
			
            $db_ex = new db_execute($myform->generate_update_SQL($id_field, $record_id));
            
			redirect($listing);
			exit();
		}
	}
	//add form for javacheck
	$myform->addFormname('faq_edit');
	$myform->evaluate();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?=$load_header?>
<? 
$myform->checkjavascript();
$errorMsg .= $myform->strErrorField;

//lay du lieu cua record can sua doi
$db_data = new db_query("SELECT * FROM " . $fs_table . " WHERE " . $id_field . " = " . $record_id);
$row = mysql_fetch_assoc($db_data->result);
if(!$row){
    redirect($listing);
    exit;
}
?>
<script type="text/javascript">
<!--
	function removeAccents(strAccents){
        strAccents = strAccents.split('');
        strAccentsOut = new Array();
        strAccentsLen = strAccents.length;
        var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
        var accentsOut = ['A','A','A','A','A','A','a','a','a','a','a','a','O','O','O','O','O','O','O','o','o','o','o','o','o','E','E','E','E','e','e','e','e','e','C','c','D','I','I','I','I','i','i','i','i','U','U','U','U','u','u','u','u','N','n','S','s','Y','y','y','Z','z'];
        for (var y = 0; y < strAccentsLen && y < 100; y++) {
            if (accents.indexOf(strAccents[y]) != -1) {
                strAccentsOut[y] = accentsOut[accents.indexOf(strAccents[y])];
            }
            else
                strAccentsOut[y] = strAccents[y];
        }
        strAccentsOut = strAccentsOut.join('');
        return strAccentsOut;
    }
    $(document).ready(function(){
        $('#fac_name').keyup(function(){
            var $alias = removeAccents($('#fac_name').val().replace(/ /g, '-'));
            $('#fac_alias').val($alias);
        });
    });
-->
</script>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<? /*------------------------------------------------------------------------------------------------*/ ?>
<?=template_top(translate_text("Edit_category"))?>
<? /*------------------------------------------------------------------------------------------------*/ ?>
	<p align="center" style="padding-left:10px;">
    <?php
    $form = new form();
    $form->create_form("faq_edit", $_SERVER["REQUEST_URI"], "post", "multipart/form-data",'onsubmit="validateForm(); return false;"');
	$form->create_table();
	?>
	<?=$form->text_note('Những ô dấu (<font class="form_asterisk">*</font>) là bắt buộc phải nhập.')?>
	<?=$form->errorMsg($errorMsg)?>
    
	<?=$form->text("Tên danh mục", "fac_name", "fac_name", $row['fac_name'], "Tên danh mục", 1, 250, "", 255, "", "", "")?>
    <?=$form->text("Alias", "fac_alias", "fac_alias", $row['fac_alias'], "Alias", 1, 250, "", 100, "", "", "")?>
    <?=$form->select("Chọn nhóm", "fac_fg_id", "fac_fg_id", $fqgop, $row['fac_fg_id'], "Chọn nhóm", 0, 250, 1, 0,  "", "")?>
    
	<?=$form->button("submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "Cập nhật" . $form->ec . "Làm lại", "Cập nhật" . $form->ec . "Làm lại", 'style="background:url(' . $fs_imagepath . 'button_1.gif) no-repeat"' . $form->ec . 'style="background:url(' . $fs_imagepath . 'button_2.gif)"', "");?>
	<?=$form->hidden("action", "action", "edit", "");?>
    
	<?
	$form->close_table();
	$form->close_form();
	unset($form);
	?>
	</p>
<?=template_bottom() ?>
<? /*------------------------------------------------------------------------------------------------*/ ?>
</body>
</html>